let id = 0
export default class Dep {
  constructor() {
    this.subs = [] // 用来存放watcher
    this.id = id++
  }

  depend() {
    // console.log(123)
    Dep.target && Dep.target.addDep(this)
  }

  addSub(watcher) {
    this.subs.push(watcher)
    console.log(this.subs)
  }

  // notify通知观察者
  notify() {
    this.subs.forEach(watcher => {
      watcher.update()
    })
  }
}
// 中专当前watcher
Dep.target = null

export function pushTarget (watcher) {
  Dep.target = watcher
}

export function popTarget () {
  Dep.target = null
}
